<template>
  <div class="tiktokopening">
    <a-card :bordered="false" style="border-radius:8px;margin-top:10px">
      <div class="card_title">
        抖音橱窗
      </div>
      <div class="groupbox flex row_bet flex_wrap" style="margin-bottom: 19px">
        <a-radio-group v-model="status" style="margin-bottom:5px;" @change="statusChange">
          <a-radio-button :value="3">
            全部
          </a-radio-button>
          <a-radio-button :value="1">
            已处理
          </a-radio-button>
          <a-radio-button :value="2">
            未处理
          </a-radio-button>
        </a-radio-group>
        <div>
          <a-input-search
            placeholder="商品ID / 店铺名"
            style="width: 200px;margin-right:10px;margin-bottom:5px;"
            v-model="search"
            allowClear
            @search="onSearch"
          />
          <a-button type="primary" icon="plus" @click="drawershow = true" class="br4">
            添加信息
          </a-button>
        </div>
      </div>
      <a-table
        :columns="columns"
        :rowKey="activity => activity.id"
        :dataSource="activity"
        :loading="loading"
        @change="handleTableChange"
        :pagination="pagination"
      >
        <div slot="active" slot-scope="row">
          <div>
            <a-button type="link" @click="doedit(row)">编辑</a-button>
          </div>
          <a-button type="link" @click="goaudit(row)">删除</a-button>
        </div>
      </a-table>
    </a-card>
    <a-drawer
      title="添加信息"
      :width="513"
      :visible="drawershow"
      :body-style="{ paddingBottom: '80px' }"
      @close="onClose"
    >
      <div class="drawer1">
        <div class="titles">产品名字</div>
        <a-input v-model="form.shoptitle" placeholder="产品名字" class="chooseipt br4"/>
        <div class="titles">商品链接</div>
        <a-textarea v-model="form.shopurl" :rows="4" class="chooseipt br4" allowClear>
        </a-textarea>
        <div
          :style="{
            position: 'absolute',
            right: 0,
            bottom: 0,
            width: '100%',
            borderTop: '1px solid #e9e9e9',
            padding: '10px 16px',
            background: '#fff',
            textAlign: 'right',
            zIndex: 1
          }"
        >
          <a-button type="primary" style="float:left;" :loading="btnloading" class="br4" @click="dosubmit">
            提 交 数 据
          </a-button>
        </div>
      </div>
    </a-drawer>
  </div>
</template>

<script>
  import { doaddtiktodata, gettiktodata, updatetiktodata } from '@/api/dockingApi'
  import moment from 'moment'

  export default {
    name: 'Tiktokopening',
    data () {
      return {
        moment,
        drawershow: false,
        status: 3,
        search: '',
        form: {
          shoptitle: '',
          shopurl: ''
        },
        titleList: [],
        columns: [
          {
            title: '日期',
            align: 'left',
            dataIndex: 'addDate',
            scopedSlots: {
              customRender: 'addDate'
            }
          },
          {
            title: '产品标题',
            align: 'center',
            dataIndex: 'shoptitle',
            scopedSlots: {
              customRender: 'shoptitle'
            }
          },
          {
            title: '产品链接',
            align: 'center',
            dataIndex: 'shopurl',
            scopedSlots: {
              customRender: 'shopurl'
            }
          },
          {
            title: '抖音号',
            align: 'center',
            dataIndex: 'douyin',
            scopedSlots: {
              customRender: 'douyin'
            }
          },
          {
            title: '处理时间',
            align: 'center',
            dataIndex: 'handleDate',
            scopedSlots: {
              customRender: 'handleDate'
            }
          },
          {
            title: '操作',
            align: 'center',
            scopedSlots: {
              customRender: 'active'
            }
          }
        ],
        activity: [
          {
            id: 4125, // 自增id
            addDate: '2020-05-08', // 添加时间
            shoptitle: '懒人挂脖子风扇三代大风力可换电池学生便携式新品带香薰充电小型', // 商品名称
            shopurl: 'https://detail.tmall.com/item.htm?id=617844606661', // 商品地址
            user: '从雪艳', // 用户
            douyin: '居家ok8868', // 抖音号
            handleDate: '2020-05-08', // 处理时间
            braId: 1 // 站点
          }
        ],
        loading: false,
        pagination: {
          pageSize: 15,
          page: 1
        },
        value: '',
        btnloading: false
      }
    },

    computed: {},
    created () {
      this.gettiktodata(1, 15, 4)
    },
    mounted () {
    },
    methods: {
      doedit (row) {
        console.log(row)
        this.form = row
        this.drawershow = true
      },
      onClose () {
        this.form = {}
        this.drawershow = false
      },
      goaudit (row) {
        console.log('删除', row)
      },
      handleChange2 (info) {
        const status = info.file.status
        // fin_fileName
        if (status !== 'uploading') {
          console.log(info.file, info.fileList)
          this.form.fin_fileName = '//' + info.file.response.data.url
        }
        if (status === 'done') {
          this.$message.success(`${info.file.name} 上传成功!`)
        } else if (status === 'error') {
          this.$message.error(`${info.file.name} 上传失败!`)
        }
      },
      dosubmit () {
        this.btnloading = true
        console.log(this.form)
        if (!this.form.id) {
          if (
            this.form.shoptitle !== '' &&
            this.form.shopurl !== ''
          ) {
            doaddtiktodata(this.form).then(res => {
              console.log(res)
              if (res.code === 200) {
                this.$message.success('提交成功!')
                this.gettiktodata(1, 15, 3)
                this.drawershow = false
                this.form = {}
                this.btnloading = false
              } else {
                this.btnloading = false
                this.$message.error(res.msg)
              }
            }).catch(err => {
              console.log(err)
            })
          } else {
            this.$message.info('请检查所需条件!')
          }
        } else {
          updatetiktodata(this.form).then(res => {
            // console.log(res)
            if (res.code === 200) {
              this.$message.success('修改成功!')
              this.gettiktodata(1, 15, 4)
              this.drawershow = false
              this.form = {}
              this.btnloading = false
            } else {
              this.btnloading = false
              this.$message.error(res.msg)
            }
          }).catch(err => {
            console.log(err)
          })
        }
      },
      gettiktodata (page, pagesize, status, search) {
        this.loading = true
        gettiktodata({
          page: page,
          pagesize: pagesize,
          status: status, // 1未审批，2审批未打款，3已打款
          search: search
        })
          .then(res => {
            console.log(res)
            this.activity = res.data.data
            //  this.count = res.data.count
            const pagination = {
              ...this.pagination
            }
            pagination.total = res.data.count
            this.pagination = pagination
            this.loading = false
          })
          .catch(err => {
            console.log(err)
          })
      },
      handleTableChange (pagination, filters) {
        // console.log(pagination)
        const pager = {
          ...this.pagination
        }
        pager.current = pagination.current
        this.pagination = pager
        this.fetch({
          results: pagination.pageSize,
          page: pagination.current,
          ...filters
        })
      },
      fetch (params = {}) {
        // console.log('params:', params)
        this.loading = true
        this.gettiktodata(params.page, 15, this.status, this.search)
      },
      onSearch (value) {
        console.log(value)
        this.gettiktodata(1, 15, this.status, this.search)
      },
      statusChange (e) {
        // console.log('radio checked', e.target.value)
        this.gettiktodata(1, 15, this.status, this.search)
      },
      titleChange (value) {
        // console.log(`selected ${value}`)
        this.form.fin_shopName = value
      }
    }
  }
</script>
<style lang="less">
  .drawer1 {
    .titles {
      color: rgba(16, 16, 16, 100);
      font-size: 13px;
      text-align: left;
      margin-bottom: 8px;
    }

    .chooseipt {
      width: 100%;
      margin-bottom: 25px;
    }

    /deep/ .ant-input {
      border-radius: 4px;
    }

    /deep/ .ant-select-selection {
      border-radius: 4px;
    }
  }
</style>
<style lang="less" scoped>
  .tiktokopening {
    .card_title {
      color: rgba(16, 16, 16, 100);
      font-size: 14px;
      margin-bottom: 15px;
      font-weight: 600;
    }

    .groupbox {
      /deep/ .ant-input {
        border-radius: 4px;
      }
    }

    /deep/ .ant-table-tbody {
      font-size: 13px;
    }
  }
</style>
